<template>
  <div>
    <!-- 面包屑   -->
    <div style="margin-bottom: 30px">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>承运商运营记录</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- 表的主体   -->
    <el-table :data="tableData" border stripe
              @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="40">
      </el-table-column>
      <el-table-column prop="id" label="id">
      </el-table-column>
      <el-table-column prop="orderId" label="订单id">
      </el-table-column>
      <el-table-column prop="transType" label="运输类型">
        <template slot-scope="scope">
          {{scope.row.transType|showtype}}
        </template>
      </el-table-column>
      <el-table-column prop="routeTbl.dedicatedLine" label="专线名称">
      </el-table-column>
      <el-table-column prop="vehicleId" label="车辆id">
      </el-table-column>
      <el-table-column prop="trainName" label="火车名字">
      </el-table-column>

    </el-table>
    <!-- 页码导航栏   -->
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[5, 10, 15, 20]"
          :page-size=pageSize
          layout="total, sizes, prev, pager, next, jumper"
          :total=total>
      </el-pagination>
    </div>
  </div>


</template>


<script>
import {CodeToText, regionData, TextToCode} from "element-china-area-data";
import request from "@/utils/request";
import {country} from "@/js/country";

export default {
  name: "Address",
  data() {
    return {
      tableData: [],
      currentPage: 1,
      name: "",
      username: "",
      gender: "",
      pageSize: 5,
      total: 0,
      dialogFormVisible: false,
      btnText: "",
      route: {},
      multipleSelection: [],
      companies: [],
    }
  },
  created() {
    this.load();
    request.get("/company/getall").then(res => {
      this.companies = res.data
    })
  },
  filters: {
    showtype(s) {
      if (s) {
        return '铁路'
      } else {
        return '汽运'
      }
    }
  },
  methods: {
    // 分页查询接口
    load() {
      request.get("/transInfo",
          {params: {pageNum: this.currentPage, pageSize: this.pageSize}}
      ).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total
        this.currentPage = res.data.current
        this.pageSize = res.data.size
      })
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      this.currentPage = pageNum
      this.load()
    },
    // 增加修改数据接口
    // 单个删除
    del(id) {
      request.delete("/route/" + id).then(res => {
        if (res.code === 200) {
          this.$message.success("删除成功")
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
      console.log(id)
    },
    handleSelectionChange(val) {
      // console.log(val)
      this.multipleSelection = val
    },
    // 批量删除接口
    delBatch() {
      //map函数：数组的每个元素都执行一个给定的函数，返回值仍为一个数组
      let ids = this.multipleSelection.map(v => v.id)
      console.log(ids)
      if (ids.length !== 0) {
        request.delete("/route/" + ids.toString(),).then(res => {
          if (res) {
            this.$message.success("批量删除成功")
            this.load()
          } else {
            this.$message.error("批量删除失败")
          }
        })
      } else {
        this.$message.warning("请选择要删除的数据")
      }
    },
    reset() {
      this.load()
    },
  }
}
</script>

<style scoped>

</style>


